package com.example.it.looker.utils;

import okhttp3.OkHttpClient;
import okhttp3.Response;

/**
 * Created by 鲁迅认识的那只猹 on 9/1/2017 8:33 AM.
 * Emial 1258730808@qq.com
 * Desc:
 */

/**
 * 网络请求的帮助类
 */
public class NetUtil {
    /**
     * 发送GET请求
     */
    public static String getRequest(String apiUrl) {
        try {

            //region 莫名出错的HTTPURLconnection
            //            URL url = new URL(apiUrl);
//            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//            connection.setRequestMethod("GET");
//
//            InputStream inputStream = connection.getInputStream();
//            int responseCode = connection.getResponseCode();
//            L.i("getRequest-ResponseCode:" + responseCode);
            //endregion

            L.i(apiUrl);

            okhttp3.Request request = new okhttp3.Request.Builder().url(apiUrl).build();
            Response response = new OkHttpClient().newCall(request).execute();
            String content = response.body().string();
            return content;
        } catch (Exception e) {
            e.printStackTrace();
            L.i("NetUtil.getRequest : Error");
            return null;
        }
    }


}